#!/usr/bin/env python
"""
给所有用户授予SSH权限
"""
import os
import django

# 设置Django环境
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
django.setup()

from django.contrib.auth.models import User
from cmdb.models import UserProfile

def grant_ssh_permissions():
    """给所有用户授予SSH权限"""
    users = User.objects.all()
    
    for user in users:
        profile, created = UserProfile.objects.get_or_create(user=user)
        
        if not profile.can_use_ssh:
            profile.can_use_ssh = True
            profile.save()
            status = "✅ 已授予SSH权限"
        else:
            status = "✓ 已有SSH权限"
        
        print(f"{user.username} - {status}")
    
    print(f"\n完成！共处理 {users.count()} 个用户")

if __name__ == '__main__':
    grant_ssh_permissions()
